package com.ll.genericHomework;

import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * @author 刘龙
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) {

    }

    @Test
    public void test1() {
        Dao<User> dao = new Dao<>();
        dao.save("001", new User(1, 10, "jack"));
        dao.save("002", new User(2, 20, "king"));
        dao.save("003", new User(3, 38, "ll"));


        List<User> list = dao.list();
        // [User{id=1, age=10, name='jack'}, User{id=2, age=20, name='king'}, User{id=3, age=38, name='ll'}]
        System.out.println(list);

        // 修改
        dao.update("003", new User(3, 38, "LL"));
        // 删除
        dao.delete("001");

        //修改后
        list = dao.list();
        // [User{id=2, age=20, name='king'}, User{id=3, age=38, name='LL'}]
        System.out.println(list);

        User user = dao.get("003");
        // User{id=3, age=38, name='LL'}
        System.out.println(user);

    }
}

class User {
    private int id;
    private int age;
    private String name;

    public User() {
    }

    public User(int id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}
